﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
#include<assert.h>

typedef int SLTDataType;
typedef struct SListNode//节点结构包括：一个节点包括数据和下一个节点地址
{
    SLTDataType data; //节点数据
    struct SListNode* next; //指针变量⽤来保存下⼀个节点的地址
}SLTNode;

//链表打印
void SLTPrint(SLTNode* phead)
{
    SLTNode* pcur = phead;
    while (pcur)
    {
        printf("%d ", pcur->data);
        pcur = pcur->next;
    }

}
//尾部插⼊
void SLTPushBack(SLTNode** pphead, SLTDataType x)
{
    assert(pphead);
    SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
    if (newnode == NULL)
    {
        perror("malloc fail");
        return;
    }
    newnode->data = x;
    newnode->next = NULL;
    if ((*pphead) == NULL)
    {
        (*pphead) = newnode;
    }
    else
    {
        SLTNode* pcur = *pphead;
        while (pcur->next)
        {
            pcur = pcur->next;
        }
        pcur->next = newnode;
    }
}

//销毁链表
void SListDesTroy(SLTNode** pphead)
{
    assert(*pphead && pphead);
    SLTNode* pcur = *pphead;
    while (pcur)
    {
        SLTNode* next = pcur->next;
        free(pcur);
        pcur = next;;
    }
    *pphead = NULL;
}

int main()
{
    SLTNode* s=NULL;
    int n = 0;
    
    scanf("%d", &n);
    int arr[256];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        SLTPushBack(&s, arr[i]);
    }
    SLTPrint(s);
    SListDesTroy(&s);
    return 0;
}

//链表的交换
#include <stdio.h>
#include<stdlib.h>
#include<assert.h>

typedef int SLTDataType;
typedef struct
SListNode { //节点结构包括：一个节点包括数据和下一个节点地址
    SLTDataType data; //节点数据
    struct SListNode* next; //指针变量⽤来保存下⼀个节点的地址
} SLTNode;

//链表打印
void SLTPrint(SLTNode* phead) {
    SLTNode* pcur = phead;
    while (pcur) {
        printf("%d ", pcur->data);
        pcur = pcur->next;
    }
}
//尾部插⼊
void SLTPushBack(SLTNode** pphead, SLTDataType x) {
    assert(pphead);
    SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
    if (newnode == NULL) {
        perror("malloc fail");
        return;
    }
    newnode->data = x;
    newnode->next = NULL;
    if ((*pphead) == NULL) {
        (*pphead) = newnode;
    }
    else {
        SLTNode* pcur = *pphead;
        while (pcur->next) {
            pcur = pcur->next;
        }
        pcur->next = newnode;
    }
}
//销毁链表
void SListDesTroy(SLTNode** pphead) {
    assert(*pphead && pphead);
    SLTNode* pcur = *pphead;
    while (pcur) {
        SLTNode* next = pcur->next;
        free(pcur);
        pcur = next;;
    }
    *pphead = NULL;
}
SLTNode* swap(SLTNode* phead)
{
    SLTNode* first = phead;
    SLTNode* second = first->next;
    if (first->next == NULL)
    {
        return first;
    }
    else {
        first->next = second->next;
        second->next = first;
        SLTNode* pre = NULL;
        SLTNode* start = second;
        SLTNode* next = second->next;
        while (next->next != NULL)
        {
            pre = start;
            start = next;
            next = next->next;
        }
        start->next = NULL;
        next->next = start;
        pre->next = next;
        return second;
    }

}
int main() {
    SLTNode* s = NULL;
    int n = 0;
    int arr[256];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        SLTPushBack(&s, arr[i]);
    }
    SLTNode* ret = swap(s);
    SLTPrint(ret);
    SListDesTroy(&s);
    return 0;
}